package shuaige.jdk.集合.映射表集合Map;

import java.util.HashMap;
import java.util.Map;

public class 常规Map使用HashMap {
    public static void main(String[] args) {
        遍历Map();
    }

    public static Map 创建Map() {
        Map<String, Integer> map = new HashMap<>();
        map.put("apple", 123);
        map.put("pear", 123);
        return map;
    }

    public static void 遍历Map() {
        Map<String, Integer> map = new HashMap<>();
        map.put("apple", 123);
        map.put("pear", 456);
        for (Map.Entry<String, Integer> value : map.entrySet()) {
            System.out.println("key:" + value.getKey());
            System.out.println("value:" + value.getValue());
        }
    }

    public static void 遍历Map的Key() {
        Map<String, Integer> map = new HashMap<>();
        map.put("apple", 123);
        map.put("pear", 456);
        map.put("banana", 789);
        for (String key : map.keySet()) {
            System.out.println(key);
        }
    }

    public static void 遍历Map的Values() {
        Map<String, Integer> map = new HashMap<>();
        map.put("apple", 123);
        map.put("pear", 456);
        for (Integer value : map.values()) {
            System.out.println(value);
        }
    }


}
